/********************************************************************************
 * Copyright(c) 2020-2025 VINCENT_WY All rights reserved.
 * - Filename
 * - Author  Vincent
 * - Version V1.0.0
 * - Date    2023/09/21
 * - Brief
 * - FunctionList:
 ******************************************************************************
 * History:
 *
 *
 *
 ******************************************************************************
 */

#pragma once

#include "CameraFrame.hpp"
#include <condition_variable>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
#include "ThreadPool.h"
#include "IReplayer.hpp"
#include "DispatchReplayImpl.h"

class DispatchReplayer : public IReplayer
{
public:
  DispatchReplayer(const std::string &cfg);
  ~DispatchReplayer();
  void start(const std::function<void(std::shared_ptr<CameraFrame> &&)> &,
             const std::function<void(std::shared_ptr<BevFrame> &&)> &) override;
  void stop() override;

protected:
  std::string _cfgFile{};

private:
  bool _isExit{false};
  bool _repeat{false};
  long long int _allFrameStartTime;
  std::string _rootPath{};
  dispatch::FileMap _allFileMap;
  std::vector<std::shared_ptr<DispatchReplayImpl>> _impl;
  std::unique_ptr<std::thread> _loopThread{nullptr};
  std::shared_ptr<ThreadPool> _mThreadPool{nullptr};
  void FileRead(dispatch::FileMap &map);
  void creatReplayImpl();
  void loop();
};